<?php
require_once(ROOT . LIBRARY .'/fields/common.inc');

class fields_logic extends fields_common implements field
{
   /**
    * Normalize Value
    *
    * @param mixed $value
    * @param string $lang
    */
   public function normalizeValue($value, $lang = null)
   {
      $this->value = (bool)$value;
      
      return $this->value;
   }

   /**
    * Get HTML code for Logic fields
    *
    * @param object $data
    * @return string
    */
   public function getFieldHTML($data)
   {
      $value = $data->{$this->alias}(null);
      $html  = '<input type="hidden" name="f['. $this->alias .']" value="0" />';
      $html .= '<input type="checkbox" name="f['. $this->alias .']';
      $html .= '" id="f_'. $this->alias .'" value="1"';
      $html .= ($value == true ? ' checked="checked"' : '');
      $html .= ' />';

      return $html;
   }

   public function validateInput($value, $objectData = NULL)
   {
      $this->value = empty($value) ? 0 : 1;
      return $this->value;
   }
}
